<?php

/**
 * This is the model class for table "{{vessel}}".
 *
 * The followings are the available columns in table '{{vessel}}':
 * @property string $id
 * @property string $registration_number
 * @property integer $ue_number
 * @property string $name
 * @property string $competence
 * @property string $competent_office
 * @property double $tsl
 * @property integer $gt
 * @property double $lft
 * @property string $lft_class
 * @property double $power
 * @property integer $construction_year
 * @property string $office
 * @property string $system
 * @property string $sample
 *
 * The followings are the available model relations:
 * @property Trip[] $trips
 */
class Vessel extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Vessel the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{vessel}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name', 'required'),
			array('ue_number, gt, construction_year', 'numerical', 'integerOnly'=>true),
			array('tsl, lft, power', 'numerical'),
			array('registration_number', 'length', 'max'=>9),
			array('name, office', 'length', 'max'=>256),
			array('competence', 'length', 'max'=>2),
			array('competent_office', 'length', 'max'=>4),
			array('lft_class', 'length', 'max'=>6),
			array('system, sample', 'length', 'max'=>15),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, registration_number, ue_number, name, competence, competent_office, tsl, gt, lft, lft_class, power, construction_year, office, system, sample', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'trips' => array(self::HAS_MANY, 'Trip', 'vessel_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'registration_number' => 'Registration Number',
			'ue_number' => 'Ue Number',
			'name' => 'Name',
			'competence' => 'Competence',
			'competent_office' => 'Competent Office',
			'tsl' => 'Tsl',
			'gt' => 'Gt',
			'lft' => 'Lft',
			'lft_class' => 'Lft Class',
			'power' => 'Power',
			'construction_year' => 'Construction Year',
			'office' => 'Office',
			'system' => 'System',
			'sample' => 'Sample',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('registration_number',$this->registration_number,true);
		$criteria->compare('ue_number',$this->ue_number);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('competence',$this->competence,true);
		$criteria->compare('competent_office',$this->competent_office,true);
		$criteria->compare('tsl',$this->tsl);
		$criteria->compare('gt',$this->gt);
		$criteria->compare('lft',$this->lft);
		$criteria->compare('lft_class',$this->lft_class,true);
		$criteria->compare('power',$this->power);
		$criteria->compare('construction_year',$this->construction_year);
		$criteria->compare('office',$this->office,true);
		$criteria->compare('system',$this->system,true);
		$criteria->compare('sample',$this->sample,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}